home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14970 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  62 lines

  1. Path: loki.tor.hookup.net!news
  2. From: David Williams <dwilliam@micromedia.on.ca>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: "Overlapping Objects"
  5. Date: Tue, 16 Apr 1996 09:22:22 -0400
  6. Organization: Micromedia Limited
  7. Message-ID: <31739F0E.69B6@micromedia.on.ca>
  8. References: <31714280.201A@micromedia.on.ca> <4ks0lo$b1n@inet-nntp-gw-1.us.oracle.com>
  9. NNTP-Posting-Host: keeper.mmltd.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Just to clarify what I meant:
  16.  
  17. Given 
  18.  
  19.     char s[]="abcdefghijklmnop";
  20.     char *sp1=&s[2];
  21.     char *sp2=&s[4];
  22.  
  23. if you strcpy(sp1,sp2) [not strcat(), as below], will the results be 
  24. as expected ("abefghijklmnop"), or will there be problems because the copy
  25. is copying over part of what it was originally copying from?
  26.  
  27. William Kaufman wrote:
  28. > In article <31714280.201A@micromedia.on.ca> Richard Steadman 
  29. > <rsteadma@micromedia.on.ca> writes:
  30. > ] Hello.
  31. > ]
  32. > ] I have a question which is quite simple, but I can't seem to find
  33. > ] the right answer anywhere.
  34. > ]
  35. > ] I'm trying to figure out when it is necessary to use the memmove()
  36. > ] function when copying strings. K&R and the man page says to use it
  37. > ] when the "objects overlap". But I can't find a formal definition
  38. > ] for this phrase (it's not in the FAQ either -- I checked!).
  39. >     If you've got two pointers into the same piece of memory, they
  40. > overlap if either pointer is in the middle of the other's region (i.e.,
  41. > between the other pointer and that pointer plus the size you're
  42. > copying).
  43. > ] Here's the scenario: I have a string, and want to copy the tail of
  44. > ] it to an earlier part of the string. The two pieces are *not*
  45. > ] overlappng when the function is called, but they may be when the
  46. > ] copy is finished.
  47. > ]
  48. > ] Given this, it safe to use strcat() instead of memmove()?
  49. >     I'm not sure I understand--they either overlap or they don't, and
  50. > asking _at what time_ fixed chunks of memory overlap doesn't make sense
  51. > to me.  But I think your answer is "No".
  52. >                                            -- Bill K.
  53. > Bill Kaufman             | "I mean ... it's not even been a two-and-two-make-
  54. > wkaufman@us.oracle.com   |  five sort of day, it's more like a two-and-two-
  55. >                          |  make ... *fish* ..."  -- "Cages", Dave McKean
  56.